/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.model.disc.parametricintegration;

import java.util.ArrayList;
import java.util.ListIterator;

import br.ufmg.dees.insane.model.disc.integrationpoint.IntegrationPoint;
import br.ufmg.dees.insane.model.disc.pointforce.PointForce;
import br.ufmg.dees.insane.model.disc.shape.Shape;
import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;

/**
*A class representing the parametric integration.<p>
*
*@author Lucas, Marcelo & Pitangueira, Roque
*@version 1.0
*@since Jully 2004
*/

public abstract class ParametricIntegration
{
	/** The type of this ParametricIntegration.*/
	protected String type;
	
	/** The shape function of this ParametricIntegration.*/
	protected Shape shape;
	
	/** The point forces of this ParametricIntegration.*/
	protected ArrayList<PointForce> pointForces = new ArrayList<PointForce>();
	
	/** The element thickness. That variable will be always 1 for solid elements.*/
	protected double elmThickness = 1;
	
	/** Return the integration order of this Equivalent Nodal Load.
	*@return the integration order of this Equivalent Nodal Load.
	*/
	public abstract int getIntegrationOrder();
	
	/** Return the transformation factor to the natural system and cartesian system.
	*@param ip The IntegrationPoint that will be used for the calculation of transformation factor.
	@return double The transformation factor to the natural system and cartesian system.
	*/
	protected abstract double getTransformationFactor(IntegrationPoint ip);
	
	/** Return the parametric integration due to any load.
	*@return parIn The ArrayList with PointForces representing the parametric integration.
	*/
	public abstract ArrayList getIntegralF();
	
	/** Return the ArrayList containing the parametric integration due to any load.
	*@return pointForces The ArrayList containing many PointForce according the number of nodes. Each PointForce holds one parametric integration.
	*/
	public abstract ArrayList getIntegralFTimesX();
	
//********************************************************************************

	/** Return the type of this ParametricIntegration.
	*@return type The type of this ParametricIntegration.
	*/
	public String getType()
	{
		return type;
	}
	
	/** Set the type of this ParametricIntegration.
	*@param a The Stirng representing the type of this ParametricIntegration
	*/
	public void setType(String a)
	{
		type = a;
	}
	
//********************************************************************************
	
	/** Returns the Shape of this ParametricIntegration.
	*@return The Shape of this ParametricIntegration.
	*/
	protected Shape getShape()
	{
		return (shape);
	}
	
	/** Sets the Shape of this ParametricIntegration.
	*@param a The Shape of this ParametricIntegration.
	*/
	protected void setShape(Shape a)
	{
		shape = a;
	}
	
//********************************************************************************
	
	/** Returns the PointForcesList of this ParametricIntegration.
	*@return The PointForcesList of this ParametricIntegration.
	*/
	public ArrayList getPointForcesList()
	{
		return (pointForces);
	}
	
	/** Sets the PointForcesList of this ParametricIntegration.
	*@param a The PointForcesList of this ParametricIntegration.
	*/
	public void setPointForcesList(ArrayList<PointForce> a)
	{
		pointForces = a;
	}
	
	/** Returns the PointForce in the specified position of the PointForcesList of this ParametricIntegration.
	*@param a The position of the PointForce desired in the PointForcesList.
	*@return The PointForce in the specified position of the PointForcesList of this ParametricIntegration.
	*/
	public PointForce getPointForce(int a)
	{
		return ((PointForce) pointForces.get(a));
	}
	
	/** Returns the PointForce with the specified label.
	*@param a The label of the PointForce desired.
	*@return The PointForce with the specified label.
	*/
	public PointForce getPointForce(String a)
	{
		PointForce pf;
		ListIterator pfs = pointForces.listIterator();
		while (pfs.hasNext())
		{
			pf = (PointForce) pfs.next();
			if (pf.getLabel() == a)
			{
				return (pf);
			}
		}
		return (null);
	}
	
	/** Adds the specified PointForce to the PointForcesList.
	*@param a The PointForce to be added to the pointForcesList.
	*/
	public void add(PointForce a)
	{
		pointForces.add(a);
	}
	
//********************************************************************************
	
	protected double getElmThickness()
	{
		return elmThickness;
	}
	
	protected void setElmThickness(double a)
	{
		elmThickness = a;
	}
	
//********************************************************************************
	
	protected IVector fillVectorX(IVector x)
	{
		PointForce pf;
		ListIterator pointforces = this.getPointForcesList().listIterator();
		int a = 0;
		while(pointforces.hasNext())
		{
			pf = (PointForce) pointforces.next();
			x.setElement(a, pf.getCoord().x);
			a++;
		}
		return x;
	}
	
//********************************************************************************
	
	public static void imprimeVetor(IVector a)
	{
		for (int i = 0; i < a.getSize(); i++)
		{
			System.out.println();
			System.out.print(a.getElement(i));
			System.out.print("\t");
		}
		System.out.println("TAMANHO DO VETOR: "+a.getSize());
	}
	
	

	public static void imprimeMatriz(IMatrix a)
	{
		for (int i = 0; i < a.getNumRow(); i++)
		{
			System.out.println();
			for (int j = 0; j < a.getNumCol(); j++)
			{
				System.out.print(a.getElement(i, j));
				System.out.print("\t");
			}
		}
		System.out.println("TAMANHO DA MATRIZ: "+a.getNumRow()+" x "+a.getNumCol());
	}
	
//********************************************************************************

}
